const tbody = document.querySelector('#shop-tbody')
getList()
function getList () {
  // 请求后端拿到商品列表渲染表格
  // 相对路径写法取决于将来在哪里用
  // 在首页发请求，所以这里不需要返回上一级
  utils.fetch('./api/shop/select.php').then(resp => {
    if (resp.code === 200) {
      const { list } = resp.body
      tbody.innerHTML = list.reduce((html, shop, index) => {
        html += `
          <tr data-id="${shop.Id}" class="hid">
            <td>${index + 1}</td>
            <td><span>${shop.name}</span><input type="text"></td>
            <td><span>${shop.price}</span><input type="text"></td>
            <td><span>${shop.num}</span><input type="text"></td>
            <td>
              <button class="btn btn-xs btn-info btn-edit">编辑</button>
              <button class="btn btn-xs btn-danger btn-del">删除</button>
              <button class="btn btn-xs btn-success btn-ok">确定</button>
              <button class="btn btn-xs btn-warning btn-cancel">取消</button>
            </td>
          </tr>
        `
        return html
      }, '')
    }
  })
}
